package com.dingup.mock.bean.speaking;


import com.dingup.mock.enums.SpeakingQuestionTypeEnum;
import com.google.gson.Gson;

import java.util.HashMap;

import static com.dingup.mock.util.ConstUtil.*;


/**
 * Created by yanggavin on 16/4/23.
 * 注:具体的问题xml数据结构
 <root>
     <title>
         <script>题目原文</script>
         <audio>题目音频URL</audio>
     </title>
     <type>Q1/Q2/Q3/Q4/Q5/Q6</type>
     <time>
         <prepare>15</prepare>
         <answer>45</answer>
     </time>
     <expl>
         <script>老师参考音频原文</script>
         <audio>老师参考音频URL</audio>
     </expl>
     <integrated>
         <reading>
             <audio>综合体阅读音频URL</audio>
             <title>阅读标题</title>
             <content>阅读内容</content>
         </reading>
         <listening>
             <pic>听力部分图片URL</pic>
             <audio>听力部分音频URL</audio>
         </listening>
     </integrated>
 </root>
 */
public class SpeakingQuestionXml {
    private HashMap<String, String> title;
    private SpeakingQuestionTypeEnum type;
    private HashMap<String, Integer> time;
    private HashMap<String, String> expl;
    private HashMap<String, HashMap<String, String>> integrated;

    public HashMap<String, String> getTitle() {
        return title;
    }

    public void setTitle(HashMap<String, String> title) {
        this.title = title;
    }

    public SpeakingQuestionTypeEnum getType() {
        return type;
    }

    public void setType(SpeakingQuestionTypeEnum type) {
        this.type = type;
    }

    public HashMap<String, Integer> getTime() {
        return time;
    }

    public void setTime(HashMap<String, Integer> time) {
        this.time = time;
    }

    public HashMap<String, String> getExpl() {
        return expl;
    }

    public void setExpl(HashMap<String, String> expl) {
        this.expl = expl;
    }

    public HashMap<String, HashMap<String, String>> getIntegrated() {
        return integrated;
    }

    public void setIntegrated(HashMap<String, HashMap<String, String>> integrated) {
        this.integrated = integrated;
    }

    public String toXmlString(){
        StringBuilder xmlBuilder = new StringBuilder();
        xmlBuilder.append("<root>");
        xmlBuilder.append(String.format("<title><script>%s</script><audio>%s</audio></title>",
                title.get(XML_NODE_NAME_SCRIPT), title.get(XML_NODE_NAME_AUDIO)));
        xmlBuilder.append(String.format("<type>%s</type>", type.getCode()));
        xmlBuilder.append(String.format("<time><prepare>%s</prepare><answer>%s</answer></time>",
                time.get(XML_NODE_NAME_PREPARE), time.get(XML_NODE_NAME_ANSWER)));
        xmlBuilder.append(String.format("<expl><script>%s</script><audio>%s</audio></expl>",
                expl.get(XML_NODE_NAME_SCRIPT), expl.get(XML_NODE_NAME_AUDIO)));
        xmlBuilder.append("<integrated>");
        HashMap<String, String> readingMap = integrated.get(XML_NODE_NAME_READING);
        xmlBuilder.append(String.format("<reading><title>%s</title><content>%s</content><audio>%s</audio></reading>",
                readingMap.get(XML_NODE_NAME_TITLE), readingMap.get(XML_NODE_NAME_CONTENT), readingMap.get(XML_NODE_NAME_AUDIO)));
        HashMap<String, String> listeningMap = integrated.get(XML_NODE_NAME_LISTENING);
        xmlBuilder.append(String.format("<listening><pic>%s</pic><audio>%s</audio></listening>",
                listeningMap.get(XML_NODE_NAME_PIC), listeningMap.get(XML_NODE_NAME_AUDIO)));
        xmlBuilder.append("</integrated>");
        xmlBuilder.append("</root>");
        return xmlBuilder.toString();
    }

    public String toJsonString(){
        Gson gson = new Gson();
        return gson.toJson(this);
    }
}
